package com.ktwlsoft.archivemanage.domain.business.repositoryService.study;

import com.ktwlsoft.archivemanage.domain.dao.entity.study.StudySubject;
import com.ktwlsoft.archivemanage.domain.dao.repository.study.StudySubjectMapper;
import com.ktwlsoft.archivemanage.payload.study.subject.StudySubjectPayload;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 专题
 *
 * @author Name on 2019/12/24 15:46
 * @version 1.0
 */
@Service
public class StudySubjectRepositoryService {

    @Getter
    private final StudySubjectMapper studySubjectMapper;

    public StudySubjectRepositoryService(StudySubjectMapper studySubjectMapper) {
        this.studySubjectMapper = studySubjectMapper;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_subject
     *
     * @mbg.generated
     */
    public int deleteByPrimaryKey(Long id){
        return studySubjectMapper.deleteByPrimaryKey(id);
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_subject
     *
     * @mbg.generated
     */
    public int insert(StudySubject record){
        return studySubjectMapper.insert(record);
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_subject
     *
     * @mbg.generated
     */
    public StudySubject selectByPrimaryKey(Long id){
        return studySubjectMapper.selectByPrimaryKey(id);
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_subject
     *
     * @mbg.generated
     */
    public List<StudySubject> selectAll(){
        return studySubjectMapper.selectAll();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_subject
     *
     * @mbg.generated
     */
    public int updateByPrimaryKey(StudySubject record){
        return studySubjectMapper.updateByPrimaryKey(record);
    }

    /**
     * 通过数量查询数据 on 2019/12/24 16:40
     *
     * @param num num
     * @return List<StudySubject>
     */
    public List<StudySubject> selectByLimitNum(Integer num,String type){
        return studySubjectMapper.selectByLimitNum(num,type);
    }

    public List<StudySubjectPayload> getList(String keywords, String classType,@Value("desc") String order) {
        List<StudySubjectPayload> subjects = studySubjectMapper.findPage(keywords, classType, order);
        subjects.forEach( s -> {
            int classCount = studySubjectMapper.findClassCount(s.getId());
            s.setClassCount(classCount);
        });
        return subjects;
    }
}